package com.xnyzc.lhy.resource.common.cp.dto;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 基础信息方法类
 * @author haoyfa
 *
 */
@Setter
@Getter
@Slf4j
public class BaseInfo implements Serializable{

	private static final long serialVersionUID = 2700169445103849149L;

	/**
	 * 请求备用域
	 */
	private Map<Object,Object> reqspareFile = new HashMap();

	/**
	 * 返回备用域
	 */
	private Map<Object,Object> resspareFile = new HashMap();

	@Override
    public String toString() {
        StringBuilder sbResult = new StringBuilder(128);

        sbResult.append(
            this.getClass().getName()
                + " instance (hashCode="
                + this.hashCode()
                + ")\r\n");
        sbResult.append("=========================================\r\n");

        java.lang.reflect.Field[] field = null;
        try
        {
            String strTemp = null;
            ArrayList<Class<?>> alClass = new ArrayList(6);
            Class<?> classTemp = this.getClass();
            while (!classTemp.getName().equals("java.lang.Object"))
            {
                alClass.add(classTemp);
                classTemp = classTemp.getSuperclass();
            }

            for (int i = alClass.size() - 1; i >= 0; i--)
            {
                classTemp =  alClass.get(i);
                field = classTemp.getDeclaredFields();
                if (field != null)
                {
                    for (int j = 0; j < field.length; j++)
                    {
                        field[j].setAccessible(true);

                        strTemp = field[j].getName();

                        if (!strTemp.startsWith("this"))
                        {
                            sbResult.append(field[j].getName() + " = ");
                            sbResult.append(field[j].get(this) + ";\r\n");
                        }

                    }
                }
            }
        }
        catch (Exception exp)
        {
            log.error("",exp);
        }

        return sbResult.toString();
    }
}
